﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autorent.Service.Tests.AutorentMngrServiceReference;
using System.Data.Services.Client;
using System.Configuration;

namespace Autorent.Service.Tests.MngrServiceTests
{
    class AutoRentEntitiesWithToken : AutoRentEntities
    {
        string _tokenN;
        string _tokenP;
        string _tokenName = "AuthorizationName";
        string _tokenPass = "AuthorizationPass";

        public AutoRentEntitiesWithToken(Uri address, string tokenName, string tokenPass) : base(address)
        {
            _tokenN = tokenName;
            _tokenP = tokenPass;
            SendingRequest += OnSendingRequest;
        }

        void OnSendingRequest(object sender, SendingRequestEventArgs e)
        {
            e.RequestHeaders[_tokenName] = _tokenN;
            e.RequestHeaders[_tokenPass] = _tokenP;
        }

        public static AutoRentEntitiesWithToken GetValidCtx()
        {
            return new AutoRentEntitiesWithToken(new Uri(ConfigurationSettings.AppSettings["MngrServiceUrl"]), "MainMngr", "MainPassword");
        }

        public static AutoRentEntitiesWithToken GetInvalidCtx()
        {
            return new AutoRentEntitiesWithToken(new Uri(ConfigurationSettings.AppSettings["MngrServiceUrl"]), "WrongMngr", "WrongPassword");
        }
    }
}
